{
 "cells": [
  {
   "cell_type": "code",
   "execution_count": 1,
   "id": "68a195d3-9acd-4073-b955-a72de2363a76",
   "metadata": {},
   "outputs": [
    {
     "name": "stdin",
     "output_type": "stream",
     "text": [
      "请输入年份（>=1），否则为1： 2002\n",
      "请输入月份（1~12），否则<1为1、>12为12： 2\n"
     ]
    },
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "28\n"
     ]
    }
   ],
   "source": [
    "from calendar import *\n",
    "def ndays(y,m):\n",
    "    #每个月的正常天数\n",
    "    monthDay=[31,28,31,30,31,30,31,31,30,31,30,31]\n",
    "    days = monthDay[ m-1]\n",
    "    if (m==2 and isleap(y)):\n",
    "        days+=1\n",
    "    return(days)\n",
    "#测试代码\n",
    "y=int(input(\"请输入年份（>=1），否则为1：\"))\n",
    "m=int(input(\"请输入月份（1~12），否则<1为1、>12为12：\"))\n",
    "if y<1: y=1\n",
    "if m<1: m=1\n",
    "if m>12: m=12\n",
    "print(ndays(y,m))\n"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "id": "61fafc5c-acca-48f1-85fa-27a66135c7c9",
   "metadata": {},
   "outputs": [],
   "source": []
  }
 ],
 "metadata": {
  "kernelspec": {
   "display_name": "Python 3 (ipykernel)",
   "language": "python",
   "name": "python3"
  },
  "language_info": {
   "codemirror_mode": {
    "name": "ipython",
    "version": 3
   },
   "file_extension": ".py",
   "mimetype": "text/x-python",
   "name": "python",
   "nbconvert_exporter": "python",
   "pygments_lexer": "ipython3",
   "version": "3.11.9"
  }
 },
 "nbformat": 4,
 "nbformat_minor": 5
}
